package api

import (
	"context"
	"doctor_srv/global"
	"doctor_srv/model"
	"doctor_srv/model/dao"
	pb "doctor_srv/proto"
	"github.com/google/uuid"
	"time"
)

func (d *DoctorServer) ConsultationList(ctx context.Context, req *pb.ConsultationListRequest) (resp *pb.ConsultationListResponse, err error) {

	consultation := dao.GetConsultation()

	var result []*pb.Consultation

	for _, v := range consultation {
		result = append(result, &pb.Consultation{
			Id:      int32(v.ID),
			Name:    v.Name,
			Age:     int32(v.Age),
			Sex:     int32(v.Sex),
			History: v.History,
			Intro:   v.Intro,
		})
	}
	return &pb.ConsultationListResponse{List: result}, nil
}
func (d *DoctorServer) AddConsul(ctx context.Context, req *pb.AddConsulRequest) (resp *pb.AddConsulResponse, err error) {

	Consul := model.Consultation{
		Code:    uuid.NewString(),
		Name:    req.Name,
		History: "",
		Age:     0,
		Sex:     0,
		IsNot:   0,
		Intro:   "",
		Image:   "",
		Times:   int(time.Now().Unix()),
	}
	global.DB.Create(&Consul)

	return &pb.AddConsulResponse{
		Success: true,
	}, nil
}
